package com.hundsun.aitest.util;

import java.util.concurrent.atomic.AtomicInteger;

public class TaskProgress {
    private final int total;
    private final AtomicInteger completed = new AtomicInteger(0);
    private String message;

    public TaskProgress(int total) {
        this.total = total;
    }

    public int getTotal() {
        return total;
    }

    public int getCompleted() {
        return completed.get();
    }

    public void incrementCompleted() {
        while (true) {
            int current = completed.get();
            if (current >= total) {
                break; // 如果已经达到了总数，则不再增加
            }
            if (completed.compareAndSet(current, current + 1)) {
                break; // 成功增加
            }
        }
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}
